package com.ecommerce.dal.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ecommerce.dal.dao.IRankDAO;
import com.ecommerce.dal.entity.Rank;
import com.ecommerce.dal.util.CustomHibernateDAOSupport;

@Repository("rankDAO")
public class RankDAO extends CustomHibernateDAOSupport implements IRankDAO {

	@Override
	public void save(Rank rank) {
		getHibernateTemplate().save(rank);

	}

	@Override
	public void update(Rank rank) {
		getHibernateTemplate().update(rank);

	}

	@Override
	public void delete(Rank rank) {
		getHibernateTemplate().delete(rank);

	}

	@Override
	public Rank findByRankId(int rankId) {
		List list = getHibernateTemplate().find(
				"from Rank rank where rank.rankId=?", rankId);
		return (Rank) ((list != null && list.size()>0) ?  list.get(0) : null) ;
	}

	@Override
	public List<Rank> findAllRanks() {
		List list = getHibernateTemplate().find("from Rank");
		return ((list != null && list.size()>0) ?  list : null) ;
	}

}
